package com.example.controller;

import com.example.entity.Customer;
import com.example.response.Result;
import com.example.service.CustomerService;
import com.example.utils.PageBean;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/cus")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    /**
     * 添加客户信息
     */
    @PostMapping
    public Result insert(String name,String password,Integer category,String address){
        log.info("增添客户信息");
        customerService.insert(name,password,category,address);
        return Result.success();
    }

    /**
     * 删除客户信息
     */
    @DeleteMapping("/{id}")
    public Result delete(Integer id){
        log.info("删除客户信息");
        customerService.delete(id);
        return Result.success();
    }

    /**
     * 修改客户信息
     */
    @PutMapping
    public Result update(Integer id,String name,String password,
                         Integer category,String address){
        log.info("修改客户信息");
        customerService.update(id,name,password,category,address);
        return Result.success();
    }

    /**
     * 条件查询客户信息
     */
    @GetMapping
    public Result select(@RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "10") Integer pageSize,
                         Integer id,String name,Integer category,String address){
        log.info("分页查询, 参数：{},{},{},{},{},{}",page,pageSize,id,name,category,address);
        PageBean pageBean = customerService.select(page, pageSize,id,name,category,address);
        return Result.success(pageBean);
    }
}
